#include "StdAfx.h"
#include "include/ModelInfo.h"
#include "QModelViewer.h"

ModelInfo::ModelInfo(QWidget *parent)
	: QTabWidget(parent)
{
	ui.setupUi(this);
	connect(ui.m_pAniListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
			this, SLOT(onAniItemClicked(QListWidgetItem*)));
}

ModelInfo::~ModelInfo()
{

}

void ModelInfo::setMaterialNames(const QStringList& nameList)
{
	ui.m_pMatListWidget->clear();
	QStringList::const_iterator itr = nameList.begin();
	QStringList::const_iterator end = nameList.end();
	while(itr != end)
	{
		ui.m_pMatListWidget->addItem(*itr);
		++itr;
	}	
}

void ModelInfo::setQModelViewer(QModelViewer* pModelViewer)
{
	m_pModelViewer = pModelViewer;
}

void ModelInfo::setSkeletonName( const QString& skeletonName )
{
	ui.m_pSkeletonListWidget->clear();
	ui.m_pSkeletonListWidget->addItem(skeletonName);
}

void ModelInfo::setAnimations( const QStringList& aniNameList )
{
	ui.m_pAniListWidget->clear();
	QStringList::const_iterator itr = aniNameList.begin();
	QStringList::const_iterator end = aniNameList.end();
	while(itr != end)
	{
		ui.m_pAniListWidget->addItem(*itr);
		++itr;
	}
}

void ModelInfo::onCopyMatBtnClick()
{
	QClipboard *clipboard = QApplication::clipboard();
	QString text = "";
	for(int i = 0; i < ui.m_pMatListWidget->count(); ++i)
		text += ui.m_pMatListWidget->item(i)->text() + " ";
	clipboard->setText(text);
}

void ModelInfo::onCopySkeletonBtnClick()
{
	QString text = "";
	for(int i = 0; i < ui.m_pSkeletonListWidget->count(); ++i)
		text += ui.m_pSkeletonListWidget->item(i)->text() + " ";
	QApplication::clipboard()->setText(text);
}

void ModelInfo::onAniItemClicked( QListWidgetItem* item )
{
	printf("%s\n", item->text().toLocal8Bit().data());
	m_pModelViewer->playAnimation(item->text(), ui.m_pLoopCheck->isChecked(),
		ui.m_pAniSpeedSpin->value());
}

